<!--
 * @Author: [yuantongxin]
 * @Date: 2021-10-21 14:41:09
 * @LastEditors: [yuantongxin]
 * @LastEditTime: 2021-10-25 16:33:35
 * @Description: 
-->
<template>
  <div>
    <!-- 头部开始 -->
    <div>
      <el-form :inline="true" :model="form" class="demo-form-inline">
        <el-date-picker
          value-format='timestamp'
          v-model="value1"
          type="daterange"
          align="right"
          unlink-panels
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          :picker-options="pickerOptions"
          style="margin-right: 15px"
        >
        </el-date-picker>
        <el-form-item>
          <el-select v-model="form.type" placeholder="请选择类型" clearable>
            <el-option label="充值" value="充值"></el-option>
            <el-option label="提现" value="提现"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-select v-model="form.status" placeholder="请选择状态" clearable>
            <el-option label="通过" value="通过"></el-option>
            <el-option label="不通过" value="不通过"></el-option>
            <el-option label="未审核" value="未审核"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-select v-model="form.userId" placeholder="申请人编号" clearable>
            <el-option
              :label="item.userId"
              :value="item.id"
              v-for="item in category"
              :key="item.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="toSearch">查询</el-button>
        </el-form-item>
      </el-form>
    </div>
    <!-- 头部开始 -->
    <!-- 表格开始 -->
    <div>
      <!-- {{ tableData }} -->
      <el-table :data="tableData" style="width: 100%">
        <el-table-column type="index" :index="1" label="序号" width="180">
        </el-table-column>
        <el-table-column prop="userId" label="申请人编号" width="180">
        </el-table-column>
        <el-table-column prop="applyTime" label="申请时间" width="180">
           <template slot-scope="scope">
         {{moment(scope.row.applyTime).format('YYYY-MM-DD HH:mm:SS') }}
        </template>
        </el-table-column>
        <el-table-column prop="applyType" label="变更类型" width="180">
        </el-table-column>
        <el-table-column prop="money" label="变更资金" width="180" style="color: #e65f70">
            
        </el-table-column> 
        <el-table-column prop="status" label="状态" width="180">
          <template slot-scope="scope">
            <el-tag type="success" v-if="scope.row.status==='通过'">通过</el-tag>
            <el-tag type="danger" v-else-if="scope.row.status==='不通过'">未通过</el-tag>
            <el-tag type="info" v-else>未审核</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="操作" width="180">
          <template slot-scope="scope" v-if="scope.row.status==='未审核'">
            <el-button type="text" size="small" @click="toPass(scope.row.id)" >通过</el-button>
            <el-button type="text" size="small" style="color: #e65f70"  @click="toNopass(scope.row.id)"
              >不通过</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <!-- 表格结束 -->
    <!-- 分页开始 -->
    <div style="text-align: right; margin: 5px">
      <el-pagination
      background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="params.page"
        :page-sizes="[10, 20, 30, 40]"
        :page-size="params.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </div>
    <!-- 分页结束 -->
  </div>
</template>

<script>
let moment = require('moment');

import { pageQueryAccountApply,checkPass,checkNoPass } from "@/api/audit";
export default {
  data() {
    return {
      pickerOptions: {
        shortcuts: [
          {
            text: "最近一周",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近一个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近三个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit("pick", [start, end]);
            },
          },
        ],
      },
      value1: "",
      form: {},
      tableData: [],
      params: {
        page: 1,
        pageSize: 10,
      },
      total: 0,
      category: [],
    };
  },
  created() {
    this.Customer();
    this.categoryPro();
  },
  watch: {
    params: {
      handler() {
        this.pageQueryAccountApply();
      },
      deep: true,
    },
  },
  methods: {
    moment,
      async toPass(id){
          let res = await checkPass({id})
        //   console.log(res);
      },
      async toNopass(id){
          let res = await checkNoPass({id})
      },
    async toSearch() {
      let temp = {
        ...this.params,
        ...this.form,
      };
       if(this.value1){
        temp.beginTime = this.value1[0]
        temp.endTime = this.value1[1]
      }
      for (let key in temp) {
        if (!temp[key]) {
          delete temp[key];
        }
      }
      let res = await pageQueryAccountApply(temp);
      this.tableData = res.data.list;
      this.total = res.data.total;
      // console.log(res);
    },
    // 封装
    async categoryPro() {
      let res = await pageQueryAccountApply({
        page: 1,
        pageSize: 10,
      });
      this.category = res.data.list;
    },
    async Customer() {
      let temp = {
        ...this.params,
      };
      let res = await pageQueryAccountApply(temp);
      console.log(res);
      this.tableData = res.data.list;
      this.total = res.data.total;
    },
    //  处理每页显示的条数
    handleSizeChange(pageSize) {
      //   console.log(`每页 ${pageSize} 条`);
      this.params.pageSize = pageSize;
      // this.queryPage()
    },
    // 处理当前页
    handleCurrentChange(page) {
      //   console.log(`当前页: ${page}`);
      this.params.page = page;
      // this.queryPage()
    },
  },
};
</script>

<style lang='scss' scoped>
</style>